package com.qiyu.tech.pay.event;

import com.qiyu.tech.pay.queue.handler.RedisDelayQueueHandler;
import com.qiyu.tech.pay.queue.handler.RedisReadyQueueHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author linhao
 * @Date created in 10:58 上午 2021/4/4
 */
@Slf4j
@Component
public class PayStarterEvent implements ApplicationRunner {

    @Resource
    private ApplicationContext applicationContext;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        executorService.execute(applicationContext.getBean(RedisReadyQueueHandler.class));
        executorService.execute(applicationContext.getBean(RedisDelayQueueHandler.class));
        log.info(">>>>>>>>>>delay queue handlers are working...");
    }
}
